from django.db import models
from utils.base import Base
# Create your models here.


# 课程类(免费，限免，会员)
class Kind(Base):

    title = models.CharField('分类名称',max_length=16,null=True)

    sequence = models.IntegerField('排序',null=True)

    class Meta:
        db_table = 'tb_kind'

# 课程标签表(python,java)
class Label(Base):

    title = models.CharField('标签名称',max_length=24,null=True)

    sequence = models.IntegerField('排序',null=True)

    class Meta:
        db_table = 'tb_label'

# 课程表
class Course(Base):

    title = models.CharField('课程名称',max_length=48,null=True)

    describe = models.CharField('课程描述',max_length=200,null=True)

    img = models.CharField('课程log',max_length=200,null=True)

    # 类别关系外键
    kind = models.ForeignKey(Kind,on_delete=models.SET_NULL,null=True)

    # 标签关系外键
    label = models.ForeignKey(Label,on_delete=models.SET_NULL,null=True)

    guanzhu = models.IntegerField('关注人数',default=0)

    # 阶段外键
    stage = models.ForeignKey('way.Stage',on_delete=models.SET_NULL,null=True)

    status = models.IntegerField('状态',default=0)

    class Meta:
        db_table = 'tb_course'


# 章节表
class Chapter(Base):

    title = models.CharField('章节名称',max_length=48,null=True)

    order = models.IntegerField('章节序列号',null=True)

    course = models.ForeignKey(Course,on_delete=models.SET_NULL,null=True)

    class Meta:
        db_table = 'tb_chapter'


# 小节
class Knobble(Base):

    title = models.CharField('节标题', max_length=24,null=True)

    serial_num = models.IntegerField('节序号',null=True)

    chapter = models.ForeignKey(Chapter, on_delete=models.SET_NULL, null=True)

    learn_time = models.IntegerField('学习小时', default=0)

    class Meta:
        db_table = 'tb_knobble'


# 我的课程表
class My_Courses(Base):

    user = models.ForeignKey('user.User',on_delete=models.SET_NULL,null=True)

    course = models.ForeignKey(Course,on_delete=models.SET_NULL,null=True)

    class Meta:
        db_table = 'tb_my_courses'

# 关注映射表表
class Attention(Base):
    # 关联用户外键
    user = models.ForeignKey('user.User',on_delete=models.SET_NULL,null=True)
    # 关联课程外键
    course = models.ForeignKey(Course,on_delete=models.SET_NULL,null=True)

    class Meta:
        db_table = 'tb_attention'


